package com.rr.mymoney.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "month_budget")
@SequenceGenerator(name = "month_budget_seq", sequenceName = "month_budget_seq")
public class MonthBudget implements Serializable {

    private static final long serialVersionUID = 1956255361343563666L;

    private Long id;
    private User user;
    private Integer month;
    private Integer year;
    private List<BudgetItem> items;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "month_budget_seq", strategy = GenerationType.AUTO)
    public Long getId() {
	return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Long id) {
	this.id = id;
    }

    /**
     * @return the user
     */
    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
    @JoinColumn(name = "user_id", nullable = false)
    public User getUser() {
	return user;
    }

    /**
     * @param user
     *            the user to set
     */
    public void setUser(User user) {
	this.user = user;
    }

    /**
     * @return the month
     */
    @Column(name = "month")
    public Integer getMonth() {
	return month;
    }

    /**
     * @param month
     *            the month to set
     */
    public void setMonth(Integer month) {
	this.month = month;
    }

    /**
     * @return the year
     */
    @Column(name = "year")
    public Integer getYear() {
	return year;
    }

    /**
     * @param year
     *            the year to set
     */
    public void setYear(Integer year) {
	this.year = year;
    }

    /**
     * @return the items
     */
    @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "monthBudget")
    @OrderBy("id")
    public List<BudgetItem> getItems() {
	return items;
    }

    /**
     * @param items
     *            the items to set
     */
    public void setItems(List<BudgetItem> items) {
	this.items = items;
    }
}
